package com.cxria.pattern.commandAndResponsibilityChain

class Invoker {

    String exec(String commandStr){
        String result = ''
        CommandVO vo = new CommandVO(commandStr)
        if(CommandEnum.getNames().contains(vo.getCommandName())){
            String className = CommandEnum.valueOf(vo.getCommandName()).value
            Command command = Class.forName(className).newInstance()
            result = command.execute(vo)
        } else {
            result = '无法执行命令,请检查命令格式'
        }
        result
    }

}
